package com.ruoyi.project.sysmanage.controller;

import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.sysmanage.domain.Dept;
import com.ruoyi.project.sysmanage.service.SysmDeptService;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.io.Serializable;
import java.util.List;

@RestController
@RequestMapping("/sysmanage/dept")
public class SysmDeptController extends BaseController {

    @Autowired
    private SysmDeptService sysmDeptService;

    //删除科室
    @DeleteMapping("/{deptIds}")
    @PreAuthorize("@ss.hasPermi('sysmanage:dept:delete')")
    public AjaxResult deleteDepts(@PathVariable int[] deptIds){

        return toAjax(sysmDeptService.deleteDepts(deptIds));
    }
    //科室修改
    @PutMapping
    @PreAuthorize("@ss.hasPermi('sysmanage:dept:update')")
    public AjaxResult updateDept(@RequestBody Dept dept){
        //设置修改人姓名
        dept.setUpdateBy(SecurityUtils.getUsername());
       int rows = sysmDeptService.updateDept(dept);
        return null;
    }

    //新增科室
    @PreAuthorize("@ss.hasPermi('sysmanage:dept:add')")
    @PostMapping()
    public AjaxResult addDept(@RequestBody Dept dept){
        dept.setCreateBy(SecurityUtils.getUsername());
        int rows = sysmDeptService.addDept(dept);
        return toAjax(rows);
    }

    //查询科室
    @PreAuthorize("@ss.hasPermi('sysmanage:dept:query')")
    @GetMapping("/find")
    public TableDataInfo find(Dept dept){
        //分页相关,处理请求参数pageNum，pageSize 等。并使用pageHelper处理分页查询
        startPage();
        //调用service查询数据库
        List<Dept> all = sysmDeptService.findAll(dept);
        //返回
        return getDataTable(all);
    }
    /**
     * 根据部门编号获取详细信息
     */
    @PreAuthorize("@ss.hasPermi('sysmanage:dept:query')")
    @GetMapping("/{deptId}")
    public AjaxResult getById(@PathVariable int deptId)
    {
        Dept dept = sysmDeptService.getById(deptId);
        return AjaxResult.success(dept);
    }

    @GetMapping("/all")
    public AjaxResult getAll(){
        return AjaxResult.success(sysmDeptService.getAll());
    }
}


































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































